package cn.seocoo.platform.common;

import cn.seocoo.platform.base.domain.BaseBrand;
import cn.seocoo.platform.base.domain.BaseVehicleType;
import cn.seocoo.platform.base.mapper.BaseBrandMapper;
import cn.seocoo.platform.base.mapper.BaseVehicleTypeMapper;
import cn.seocoo.platform.base.service.IBaseVehicleTypeService;
import cn.seocoo.platform.car.dto.CarDto;
import cn.seocoo.platform.common.utils.AmountUtils;
import cn.seocoo.platform.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: CommonServiceImpl
 * @description: 方法调用实现抽出
 * @author: wujian
 * @Date: 2020-01-02 23:34
 **/
@Service
public class CommonServiceImpl {
    @Autowired
    private BaseVehicleTypeMapper baseVehicleTypeMapper;
    @Autowired
    private BaseBrandMapper baseBrandMapper;

    public void  getCarListForServcie(List<CarDto> list){
        if (StringUtils.isNotEmpty(list)) {
            for (CarDto carDto : list) {
                if (StringUtils.isNotBlank(carDto.getBaseCarriageSize())) {
                    Integer vehicleId = carDto.getVehicleId();
                    BaseVehicleType baseVehicleType = baseVehicleTypeMapper.selectBaseVehicleTypeById(vehicleId);
                    carDto.setBaseCarriageSize(carDto.getBaseCarriageSize() + baseVehicleType.getDimension());
                }
                //如果车辆品牌存放的是不限
                if(carDto.getBrandId() != null){
                    if(BaseBrand.BRAND_NAME.equals(carDto.getBaseBrandName())){
                        BaseBrand baseBrand = baseBrandMapper.selectBaseBrandById(carDto.getBrandId());
                        if(baseBrand != null){
                            BaseBrand parentBrand =  baseBrandMapper.selectBaseBrandById(baseBrand.getParentId());
                            carDto.setBaseBrandName(parentBrand.getBrandName());
                        }
                    }
                }
                if(StringUtils.isNotBlank(carDto.getPicPath())){
                    carDto.setPicPath(carDto.getPicPath().split(",")[0]);
                }
                if (StringUtils.isNotBlank(carDto.getAmount())) {
                    carDto.setAmount(AmountUtils.changeF2W(carDto.getAmount()) + "万");
                }
                if (StringUtils.isNotBlank(carDto.getArrivalTime())) {
                    carDto.setArrivalTime(carDto.getArrivalTime().substring(2, 4) + "年" + carDto.getArrivalTime().substring(5, 7) + "月");
                }

            }
        }
    }
}
